package com.chris.code.generate.custom;

import com.chris.assist.builders.springboot.supports.SpringbootBuildParams;
import com.chris.assist.common.templates.ResourceMode;
import com.chris.assist.config.Config;
import com.chris.assist.models.TableInfo;
import com.chris.assist.models.TemplateData;
import com.chris.assist.test.manager.DefaultTestConfigBuilder;
import com.chris.assist.velocity.TemplateParam;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Chris Chan
 * Create On 2025/10/11 上午1:20
 * Use for: 测试自定义构建器
 * Explain:
 */
public class CustomBuildTest {
    private static final String templateRootPath = "G:\\Dev\\products\\dragon-models\\models\\projects\\pear\\assist\\templates2\\springboot";
    private static final String tablePrefix = "smp_";
    public static void main(String[] args) {
        Config config = DefaultTestConfigBuilder.create().get();
        build01(config);
    }

    private static void build01(Config config) {
        // 获取数据表列表
        List<TableInfo> tableInfoList = config.db.getTableInfoList();
        // 过滤
        List<TableInfo> collect = tableInfoList.stream()
                .filter(tableInfo -> tableInfo.name.startsWith(tablePrefix))
                .collect(Collectors.toList());
        // 获取自定义构建器
        CustomBuilder builder = CustomBuilder.get(config);
        // 构建参数
        SpringbootBuildParams buildParams = SpringbootBuildParams.of()
                .setPackageName("service.assistants.async")
                .setModelSuffix("AsyncAssistant")
                .setModelTagSuffix("异步处理助手")
                .setTemplateParam(
                        TemplateParam.of()
                                .setMode(ResourceMode.FILE)
                                .setRootPath(templateRootPath)
                                .setResourcePath("service_assistant_async.vm")
                );
        // 构建数据列表
        List<TemplateData> dataList = builder.buildDataList(collect, buildParams);
        // 创建模型类
        builder.create(dataList);
    }
}
